﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="OAclient.Common" %>

<script type="text/javascript">
    $(function() {
           $(".datepicker").datepicker();
           $("#userName").autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: "/Home/SearchUserFormAll",  //要查询的Action
                    type: "POST",  //Post提交
                    dataType: "json", //json格式数据，默认是text
                    data: { keyword: request.term }, //参数，不知道为什么？请指点
                    success: function(data) {
                        response($.map(data, function(item) {
                            return { label: item.text, value: item.value }; //将返回的jsonresult的属性赋值给autocomplete item
                        }))
                    }
                })
            },
           select: function(event, ui) {
                var t=ui.item.label;//'马军 事业部 员工'
                var arr= t.split(' ');
                $('#userName').val(arr[0]);  //选中item的文本
                $('#userid').val(ui.item.value); //选中item的值
                return false;
            },
            minLength:'0',
        })
        
        tableSelectOrder("#alluserlist .table_style");
    });
    function addUser() {
        $.ajax({
            type: "POST",
            url: "/Basic/UserAdd",
            success: function(data) {
                addtab("6-1", "添加用户");
                $("#workarea-6-1").html(data);
            }
        });
    }

</script>

<script type="text/javascript">
    function changeDept() {
        var deptId = $("#dept").val();
        if (deptId == "1") {
            alert("不能将员工移至公司部门");
            return;
        }

        var table = $("#alluserlist").children("div").children("table");
        var trcontent = $(table).children().children(".tbcontent");
        var ids = "";
        //alert(trcontent.length);
        $.each(trcontent, function(key, value) {
            var tdname = $(value).children(".tdname"); ;
            var check = $(tdname).children(".checkname").attr("checked");
            if (check == true) {
                var id = $(tdname).children(".hideid").val();
                //alert(id);
                ids += "'" + id + "',";
            }
        })

        if (ids == "") {
            alert("请先勾选需要迁移部门的员工");
            return;
        }

        $.ajax({
            type: "POST",
            url: "/Basic/ChangeDept",
            data: { "userIds": ids, "deptId": deptId },
            success: function(restag) {
                if (restag.res != true) {
                    alert(restag.msg);
                    return;
                }
                else {
                    alert("操作成功");
                    $('#menu_userlist').trigger('click');
                }
            }
        });
    }

    $(function() {
        var alluserlistoptions = {
            url: '/Basic/AllUserList',
            type: 'POST',
            success: function(data) {
                $("#alluserlist").html(data);
            }
        };
        $('#frmalluserlist').ajaxForm(alluserlistoptions);
    });
</script>

<script type="text/javascript">
    function showUserDetail(userID) {
        $.ajax({
            type: "POST",
            url: "/Basic/UserInfo",
            data: { "user_id": userID },
            success: function(data) {
                addtab('6-2-1', '用户信息');
                $("#workarea-6-2-1").html(data);
            }
        })
    }
</script>

<div id="alluserlist">
    <input class="btn_style" type="button" value="添加用户" onclick="addUser()" style="margin-top: 5px;" />
    <div id="soredLand" style="margin: 10px 20px 5px 100px;">
        <%using (Html.BeginForm("AllUserList", "Basic", FormMethod.Post, new { id = "frmalluserlist" }))
          { %>
        用户名:<%=Html.TextBox("userName")%><%=Html.Hidden("userid")%>
        时间:<%=Html.TextBox("stime", null, new { @class = "datepicker" })%>-<%=Html.TextBox("etime", null, new { @class = "datepicker" })%>
        部门名称:<%=Html.DropDownList("deptName", ViewData["dept"] as List<SelectListItem>, "==请选择==", null)%>
        状态:<select id="userstatus" name="userstatus">
            <option value="" selected="selected">默认</option>
            <option value="1">在用</option>
            <option value="0">停用</option>
        </select>
        <input class="btn_style" type="submit" value="查询" />
        <%} %>
        <%--        <input type="button" onclick="changeDept()" value="部门迁移至" />
        <%=Html.DropDownList("dept")%>--%>
    </div>
    <div id="dtuserlist">
        <table border="0" width="100%" class="table_style" cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <th>
                        姓名
                    </th>
                    <th>
                        账号
                    </th>
                    <th>
                        创建日期
                    </th>
                    <th>
                        状态
                    </th>
                    <th>
                    </th>
                </tr>
            </thead>
            <tbody>
                <%
                    System.Data.DataTable dt = ViewData["dt"] as System.Data.DataTable;
                    if (dt == null || dt.Rows.Count == 0)
                    {%>
                <tr>
                    <td colspan="0" style="text-align: center;">
                        当前无数据！
                    </td>
                </tr>
                <%}
                    else
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                %>
                <tr>
                    <td>
                        <%--  <input class='checkname' type="checkbox" />
                    <input class='hideid' type="hidden" value="<%=dt.Rows[i]["id"] %>" />--%>
                        <%=dt.Rows[i]["用户名称"]%>
                    </td>
                    <td>
                        <%=dt.Rows[i]["账号"]%>
                    </td>
                    <td>
                        <%=DateTime.Parse(dt.Rows[i]["创建时间"].ToString()).ToString("yyyy-MM-dd HH:mm")%>
                    </td>
                    <td>
                        <%=dt.Rows[i]["状态"].ToString() == "1" ? "在用" : "停用"%>
                    </td>
                    <td>
                        <a onclick="showUserDetail(<%=dt.Rows[i]["用户编码"]  %>)">查看</a>
                    </td>
                </tr>
                <%
                    }
                    } %>
            </tbody>
        </table>
    </div>
    <div id="pageLink">
        <%var pageInfo = ViewData["PagingInfo"] as PagingInfo; %>
        <%=Ajax.PageLinks(pageInfo, index => Url.Action("AllUserList", 
                new { 
                    page = index,
                    olduserName = ViewData["userName"],
                    oldstime = ViewData["stime"],
                    oldetime=ViewData["etime"],
                    olddeptName = ViewData["deptName"] ,
                    olduserstatus = ViewData["userstatus"]                
                }), new AjaxOptions { UpdateTargetId = "alluserlist" })%>
    </div>
</div>
